package org.llc.common.starter.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码编码工具类
 *
 * @author llc
 * @date 2020/2/27 11:28
 * @since 1.0.0
 */
public class BpwdEncoderUtil {
    private static final BCryptPasswordEncoder ENCODER = new BCryptPasswordEncoder();

    /**
     * 用BCryptPasswordEncoder
     * @author llc
     * @date 2019/11/26 14:35
     * @param password 密码
     * @return java.lang.String
     */
    public static String bCryptPassword(String password) {
        return ENCODER.encode(password);
    }

    /**
     * 密码匹配
     * @author llc
     * @date 2019/11/26 13:39
     * @param rawPassword 未加工密码
     * @param encodedPassword 编码后密码
     * @return boolean
     */
    public static boolean matches(CharSequence rawPassword, String encodedPassword) {
        return ENCODER.matches(rawPassword, encodedPassword);
    }

}
